﻿/*
 * File: BirdEyeViewBallChaseCamera.cs
 * Author: Gourav Das
 * Purpose: Class for BirdEyeView chase camera
 * Created: June 2011
 */

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace _22yards.ThreeD
{
    public class BirdEyeViewBallChaseCamera : BaseCamera
    {
        private Vector3 desiredPosition;
        
        public BirdEyeViewBallChaseCamera(Game game)
            : base(game)
        {
            ResetCamera();
        }

        public override void ResetCamera()
        {
            desiredPosition = new Vector3(0, 460f, -380);
            Position = new Vector3(0f, 460, -380);
            rotationMatrix = Matrix.CreateFromYawPitchRoll(0f, 1.08f, 0);
            LookAt = new Vector3(0, 0, 1);
            transformedReference = Vector3.Transform(LookAt, rotationMatrix);
            LookAt = (Position + transformedReference);
            ViewMatrix = Matrix.Identity;
            FOV = 45.0f;
            //offsetDistance = new Vector3(0, 120, 49);

        }

        public void SetFOV(float _fov)
        {
            FOV = _fov;
        }

        public void Update(GameTime _gametime, Vector3 chasedObjectsPos)
        {
            LookAt = new Vector3(0, 0, 1);
            transformedReference = Vector3.Transform(LookAt, rotationMatrix);
            LookAt = chasedObjectsPos + transformedReference;

            desiredPosition.X = chasedObjectsPos.X;
            desiredPosition.Y = 460;
            desiredPosition.Z = chasedObjectsPos.Z;
            Position = Vector3.SmoothStep(Position, desiredPosition, .055f);

            base.Update(_gametime);
        }
    }
}
